﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RaisingStudio.Data.Expressions
{
    [Serializable]
    public class ColumnExpression : OperationElement
    {
        private string columnName;
 
        #region Constructor
        public ColumnExpression(string columnName)
        {
            this.columnName = columnName;
        }
        #endregion

        public override string ToString()
        {
            return this.columnName;
        }

        #region type 转换
        public static explicit operator string(ColumnExpression value)
        {
            return value.columnName;
        }

        public static implicit operator ColumnExpression(string value)
        {
            return new ColumnExpression(value);
        }
        #endregion

        #region Function property 
        public FunctionExpression Avg
        {
            get
            {
                return new FunctionExpression(FunctionOperator.Avg, this);
            }
        }

        public FunctionExpression Count
        {
            get
            {
                return new FunctionExpression(FunctionOperator.Count, this);
            }
        }

        public FunctionExpression Max
        {
            get
            {
                return new FunctionExpression(FunctionOperator.Max, this);
            }
        }

        public FunctionExpression Min
        {
            get
            {
                return new FunctionExpression(FunctionOperator.Min, this);
            }
        }

        public FunctionExpression Sum
        {
            get
            {
                return new FunctionExpression(FunctionOperator.Sum, this);
            }
        }
        #endregion

        #region
        public SortingExpression OrderBy()
        {
            return new SortingExpression(this);
        }

        public SortingExpression OrderBy(SortingDirection sortingDirection)
        {            
            return new SortingExpression(this, sortingDirection);
        }
        #endregion
        #region 符重载
        public static SortingExpression operator !(ColumnExpression columnExpression)
        {
            return (!columnExpression.OrderBy());
        }
        #endregion
    }
}
